package se.talento.restlet;

import java.io.IOException;

import org.restlet.data.MediaType;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class VersionResource extends ServerResource {
    @Get("xml")
    public Representation toXml() {
        try {
            DomRepresentation representation = new DomRepresentation(MediaType.TEXT_XML);
            Document d = representation.getDocument();
            Element versionElement = d.createElement("version");
            versionElement.appendChild(d.createTextNode("1.0.0-090812-1"));
            d.appendChild(versionElement);
            d.normalizeDocument();
            return representation;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}